package com.syni.mdd.yhd.common.all.listen.groupBuy.bargain;

import com.alibaba.fastjson.JSON;
import com.syni.mdd.yhd.common.all.constants.AuroraPushCode;
import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.entity.*;
import com.syni.mdd.yhd.common.all.entity.groupBuy.BmsUserBargain;
import com.syni.mdd.yhd.common.all.entity.user.BmsUser;
import com.syni.mdd.yhd.common.all.listen.groupBuy.GroupBuyEvent;
import com.syni.mdd.yhd.common.all.service.*;
import com.syni.mdd.yhd.common.all.service.activity.BmsDrOrderLogService;
import com.syni.mdd.yhd.common.all.service.groupBuy.BmsUserBargainService;
import com.syni.mdd.sjb.common.component.utils.common.utils.BeanUtils;
import com.syni.mdd.sjb.common.component.utils.common.utils.DateTimeUtils;
import com.syni.mdd.yhd.common.all.utils.StringUtils;
import com.syni.mdd.yhd.common.all.utils.TokenManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @className OrderListener
 * @description TOO
 * @Author cfx
 * @DATE 2019/8/8 15:46
 * @VERSION 1.0
 **/
@Component
public class GroupBuyBargainListener implements ApplicationListener<GroupBuyBargainEvent> {
    private final Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    BmsDxGroupBuyService bmsDxGroupBuyService;

    @Autowired
    BmsUserBargainService bmsUserBargainService;

    @Override
    @Async
    public void onApplicationEvent(GroupBuyBargainEvent groupBuyBargainEvent) {
        BmsUserBargain bmsUserBargain = groupBuyBargainEvent.getBmsUserBargain();
        //调用saas支付接口
        //统计砍价量
        BmsDxGroupBuy bmsDxGroupBuy = bmsDxGroupBuyService.getGroupBuyById(bmsUserBargain.getGroupBuyId());
        if(bmsDxGroupBuy != null) {
            bmsDxGroupBuy.setBargainNum((bmsDxGroupBuy.getBargainNum() == null ? 0 : bmsDxGroupBuy.getBargainNum()) + 1);
            bmsDxGroupBuyService.getBaseDao().save(bmsDxGroupBuy);
        }
    }
}
